{include file="public/header" /}
<link rel="stylesheet" href="/static/admin/css/base.css" media="all">
<style>
    html {
        background-color: #f2f2f2 !important;
    }
    .layui-form-item {
        margin-bottom: 0 !important;
    }
    .underline{
        text-decoration: underline;color: #00a2d4
    }
    tr th:last-child {
        border-right: 0 !important;
    }
    .layui-card-body {

        padding: 10px 1px!important;
    }
    .nav_search{
        padding-top: 5px;
    }
    .statistics_list{
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-right: .5rem;
        padding: 5px
    }
    .statistics_list div{
        margin-left: 2rem;
        font-size: 13px;
    }
</style>
<body>
<div class="layui-fluid layui-anim layui-anim-downbit">
    <div class="layui-card">

        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">

            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="nav_search">
                        {include file="form/items/search" type='1' /}
                    </div>
                    <div class="layui-card-body">
                        <div style="display: flex;align-items: center;justify-content: space-between">
                            <div class="layui-btn-container" style="flex: 1">
                                {foreach name="top_buttons" item="vo"}
                                {if $vo.title == '导出'}
                                <a class="{$vo.class}" data-json='<?php echo json_encode($vo);?>' data-url="{:url('export',array_merge($Request.param,$extra_map))}" onclick="{$vo.onclick}">
                                    <i class="layui-icon {$vo.icon}"></i>{$vo.title}
                                </a>
                                {else}
                                <a class="{$vo.class}" data-json='<?php echo json_encode($vo);?>' onclick="{$vo.onclick}">
                                    <i class="layui-icon {$vo.icon}"></i>{$vo.title}
                                </a>
                                {/if}
                                {/foreach}

                                <a  class="layui-btn layui-bg-cyan layui-btn-sm" href="/static/admin/muban.xlsx" download="检查场所数据模板">
                                    <i class="layui-icon layui-icon-export"></i>下载数据模板
                                </a>
                                 <label  class="layui-btn layui-bg-cyan layui-btn-sm">
                                    <i class="layui-icon layui-icon-export"></i>导入场所<input type="file" id="exportAdd" data-ids="{$Request.param.id}" style=" width:100%; display:none;">
                                </label>
                            </div>
                            {if $census}
                            <div class="layui-row statistics_list">
                                {foreach name="census" item="vo" key="k"}
                                <div>{$k}：{$vo}</div>
                                {/foreach}
                            </div>
                            {/if}
                        </div>
                        <table class="layui-table" lay-data="{page:true, url:'{:url('getList', array_merge($Request.param,$extra_map))}',
            id:'formId',totalRow: {$totalRow},'cellMinWidth':80,limit:20,limits:[20,40,60,80,100] , size: 'sm',even:true,id:'form_table'}" lay-filter="table">
                            <thead>
                            <tr>
                                {foreach name="columns" item="vo"}
                                {if isset($vo.format) && $vo.format == 'password'}
                                {else}
                                <?php $data = json_encode($vo);?>
                                <th lay-data="{$data}">{$vo.title}</th>
                                {/if}
                                {/foreach}
                            </tr>
                            </thead>
                        </table>
                        <script type="text/html" id="barDemo">
                            <div class="layui-btn-container">
                                {foreach name="right_buttons" key="key" item="vo"}
                                {{#  if(d.status == '待审核'){ }}
                                <a class="{$vo.class} right_button" lay-event="{$vo.json}" style="background-color: #FF5722">审核</a>
                                {{#  } else { }}
                                <a class="{$vo.class} right_button" lay-event="{$vo.json}">{$vo.title}</a>
                                {{#  } }}
                                {/foreach}
                            </div>
                        </script>

                        <input type="hidden" id="update_url" value="{:url('update')}"/>
                        <!-- 开关状态栏 -->
                        {foreach name="switch_tool" item="vo"}
                        <script type="text/html" id="{$vo.name}">
                            <input type="checkbox" name="{$vo.name}" value="{{d.{$vo.pk}}}" lay-filter="status" lay-skin="switch" lay-text="{$vo.text}" {{ d.{$vo.name}== 1 ? 'checked' : '' }}>
                        </script>
                        {/foreach}

                        <!-- 排序Bar -->
                        {foreach name="sort_tool" item="vo"}
                        <script type="text/html" id="sort_{$vo.name}">
                            <input type="text" data-key="{$vo.name}" data-id="{{d.{$vo.pk}}}" data-url="{$vo.url}" value="{{d.{$vo.name}}}" class="layui-input x-sort tableInput"/>
                        </script>
                        {/foreach}
                        <!-- 渲染附加的html -->
                        <?php echo $extra_html;?>
                        <!--                        {$extra_html}-->
                    </div>
                </div>
                {if !empty($tab)}
                {foreach name="tab" item="vo" key="key"}
                <div class="layui-tab-item" id="tpl_{$key+2}"></div>
                {/foreach}
                {/if}
            </div>
        </div>
    </div>
</div>
</body>
{include file="public/footer" /}
{foreach name="js_url" item="vo"}
<script type="text/javascript" src="/static/admin/form/js/{$vo}.js"></script>
{/foreach}


<script src="/static/admin/js/xlsx.core.min.js"></script>
<script>
    //给input标签绑定change事件，一上传选中的.xls文件就会触发该函数
    $('#exportAdd').change(function(e) {
        var files = e.target.files;
        var fileReader = new FileReader();
        fileReader.onload = function(ev) {
            try {
                var data = ev.target.result
                var workbook = XLSX.read(data, {
                    type: 'binary'
                }) // 以二进制流方式读取得到整份excel表格对象
                var persons = []; // 存储获取到的数据
            } catch (e) {
                notify.warning("文件类型不正确");
                return false;
            }
            // 表格的表格范围，可用于判断表头是否数量是否正确
            var fromTo = '';
            // 遍历每张表读取
            for (var sheet in workbook.Sheets) {
                if (workbook.Sheets.hasOwnProperty(sheet)) {
                    fromTo = workbook.Sheets[sheet]['!ref'];
                    //console.log(fromTo);
                    persons = persons.concat(XLSX.utils.sheet_to_json(workbook.Sheets[sheet]));
                    //break; // 如果只取第一张表，就取消注释这行
                }
            }
            //在控制台打印出来表格中的数据
            if(persons.length<1) {
                notify.warning("暂无数据不可导入");
                return false;
            }
           $.post("{:url('company/importcompanyexcel')}",{persons:JSON.stringify(persons),district_id:$('#exportAdd').data('ids')},function(data,status){
                parent.layer.msg(data.msg, {time: 1000}, function () {
                    window.location.reload();
                });
            });
        };
        // 以二进制方式打开文件
        fileReader.readAsBinaryString(files[0]);
    });
</script>
</html>